import {createSlice} from "@reduxjs/toolkit";
import {HTTP} from '@/utils/HTTP.js'

const UserStore = createSlice({
    name: 'user',
    // 初始化数据
    initialState: {
        userList: []
    },
    // 同步修改状态
    reducers: {
        setUserList(state, action) {
            state.userList = action.payload
        }
    }
})

// 解构赋值
const {setUserList} = UserStore.actions
// 异步修改状态
const getUserList = () => {
    return async (dispatch) => {
        const res = await HTTP({
            url: '/admin',
            method: 'GET'
        })
        dispatch(setUserList(res.data))
    }
}

export {getUserList}
const reducer = UserStore.reducer
export default reducer